package com.wanbatv.wanba.ahitv.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.wanbatv.wanba.ahitv.R;

import java.util.Map;


public class OpenActivityAction implements View.OnClickListener {
	@SuppressWarnings("rawtypes")
	private Class activityClass;
	private Map<String, String> params;
	private Context context;

	private String mProductCode = null;
	private String mTranId = null;
	private boolean mNeedAuth = false;
	private Drawable mOrderPrimaryButtonBackground = null;
	private Drawable mOrderSecondaryButtonBackground = null;

	private View.OnClickListener mListener = null;
	private AlertDialog myDialog=null;

	public OpenActivityAction(Context context, Class activityClass,
							  Map<String, String> params) {
		this.activityClass = activityClass;
		this.context = context;
		this.params = params;
	}

	public OpenActivityAction(Context context, Class activityClass) {
		this.activityClass = activityClass;
		this.context = context;
	}

	public OpenActivityAction setOrderPrimaryButtonBackground(Drawable drawable) {
		mOrderPrimaryButtonBackground = drawable;
		return this;
	}

	public Drawable getOrderPrimaryButtonBackground() {
		return mOrderPrimaryButtonBackground;
	}

	public OpenActivityAction setOrderSecondaryButtonBackground(Drawable drawable) {
		mOrderSecondaryButtonBackground = drawable;
		return this;
	}

	public Drawable getOrderSecondaryButtonBackground() {
		return mOrderSecondaryButtonBackground;
	}

	public OpenActivityAction setNeedAuth(boolean needAuth) {
		mNeedAuth = needAuth;
		return this;
	}

	public boolean isNeedAuth() {
		return mNeedAuth;
	}

	public OpenActivityAction setProductCode(String productCode) {
		mProductCode = productCode;
		return this;
	}

	public String getProductCode() {
		return mProductCode;
	}

	public OpenActivityAction setTranId(String tranId) {
		mTranId = tranId;
		return this;
	}

	public String getTranId() {
		return mTranId;
	}

	@Override
	public void onClick(final View v) {
		if (mListener != null) {
			mListener.onClick(v);
		}

//		if (true) {
//			Intent intent = new Intent(context, activityClass);
//
//			if (params != null) {
//				for (String str : params.keySet()) {
//					intent.putExtra(str, params.get(str));
//				}
//			}
//			context.startActivity(intent);
//			return;
//		}

		if (LoginActivity.is_dinggou) {
			Intent intent = new Intent(context, activityClass);

			if (params != null) {
				for (String str : params.keySet()) {
					intent.putExtra(str, params.get(str));
				}
			}
			context.startActivity(intent);
		} else {
//			Intent it=new Intent();
//			it.setClass(context,PayActivity.class);
//			context.startActivity(it);
			creatAlertDialog_tuichu();
		}

	}

	public OpenActivityAction setOnClickListener(View.OnClickListener l) {
		mListener = l;
		return this;
	}
	private void creatAlertDialog_tuichu() {

		myDialog = new AlertDialog.Builder(context).create();

		myDialog.show();

		myDialog.getWindow().setContentView(R.layout.diolag_queding);

		myDialog.getWindow()
				.findViewById(R.id.no_iv)
				.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						myDialog.dismiss();

					}

				});
		myDialog.getWindow()
				.findViewById(R.id.yes_iv)
				.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						myDialog.dismiss();
						Intent it=new Intent();
						it.setClass(context,PayActivity.class);
						context.startActivity(it);

					}

				});
	}
}
